#include "ClientHandler.h"

ClientHandler::ClientHandler(qintptr socketDescriptor, QObject *parent)
	: QObject(parent)
{
	this->socketDescriptor = socketDescriptor;
}

ClientHandler::~ClientHandler()
{}

void ClientHandler::working()
{
	this->socket = new QTcpSocket;
	this->socket->setSocketDescriptor(this->socketDescriptor);
	QObject::connect(this->socket, &QTcpSocket::readyRead, this, &ClientHandler::receiveInfo);
}

void ClientHandler::receiveInfo()
{
	QString strMsg = this->socket->readAll();
	QString strIp = this->socket->peerAddress().toString();
	QString strPort = QString::number(this->socket->peerPort());
	emit setMsg(strMsg, strIp, strPort);
}